import {request} from '../../request/index.js'
const regeneratorRuntime = require('../../lib/runtime.js')
Page({
  data: {
    icon1:false,
    icon2:false,
    select1: false,
    select2: false,
    tihuoWay: '全年级',
    tihuoWay2: '全科目',
    background: [],
    list:[],
    indicatorDots: true,
    vertical: true,
    autoplay: true,
    circular:true,
    interval: 2000,
    duration: 500,
    userName:'牛顿',
    isShow: false,
    pageShow: false
  },
  pages() {
    this.setData({
      select1:false,
      select2:false,
      icon1:false,
      icon2:false,
    })
  },
  bindShowMsg1() {
    this.setData({
      select1:!this.data.select1,
      select2:false,
      icon1:!this.data.icon1,
      icon2:false,
      page:true,
    })
  },
  bindShowMsg2() {
    this.setData({
      select2:!this.data.select2,
      select1:false,
      icon1:false,
      icon2:!this.data.icon2,
      page:true
    })
  },
  mySelect(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      tihuoWay: name,
      select1: false,
      icon1:false,
    })
  },
  mySelect2(e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      tihuoWay2: name,
      select2: false,
      icon2:false
    })
  },
  open() {
    this.setData({
      isShow: !this.data.isShow
    })
  },
  onPageScroll(e){
    const query = wx.createSelectorQuery();
    query.select('.articleTop').boundingClientRect((rect) => {
    let top = rect.top;
    // console.info('按钮距离顶部位置', top)
    if (top <= 0) { //临界值，根据自己的需求来调整
      this.setData({
        pageShow: true, 
      })
    } else {
        this.setData({
          pageShow: false,
        })
      }
    }).exec()
  },
  onShow() {
    let that =this
    setTimeout(()=>{
      const query = wx.createSelectorQuery();
      query.selectAll('.content').boundingClientRect();
      query.exec(function(res) {
        console.log(res)
        for(let i=0;i<res[0].length;i++){
          const LineHeight = 25; // 行高
          const LineNum = res[0][i].height / LineHeight; // 行数
          if (LineNum > 2) {
            that.setData({
              lineNum: LineNum,
              isShow:true,
              idx:i
            })
            console.log(LineNum)
            console.log(i)
          } 
        }  
      })
    },1000)
  },
  async getBanner(){
    const res = await request({url:'/a/u/video/banner',method:'GET'})
    console.log(res.data)
    if(res.data.code==0){
      this.setData({
        background:res.data.data
      })
    }
  },
  async getList(){
    let param = {subject:2,page:1,size:10,grade:7}
    const res = await request({url:'/a/u/video/list',method:'GET',data:param})
    console.log(res.data)
    if(res.data.code==0){
      this.setData({
        list:res.data.data.list
      })
    }
  },
  onLoad(){
    this.getBanner()
    this.getList()
  }
})